package com.frxuexi.lib_base.net

import android.content.Context
import androidx.room.Room
import com.frxuexi.lib_base.db.CommentDao
import com.frxuexi.lib_base.db.HourseDao
import com.frxuexi.lib_base.db.ParkDataBase
import com.frxuexi.lib_base.db.SearchDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton


@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {

    @Singleton
    @Provides
    fun getApiService():ApiService=RetrofitUtil.parkRetrofit.create(ApiService::class.java)

    @Singleton
    @Provides
    fun getShopApiService():ShopApiService=RetrofitUtil.shopRetrofit.create(ShopApiService::class.java)

    @Singleton
    @Provides
    fun getHourseApiService():HourseApiService=RetrofitUtil.hourseRetrofit.create(HourseApiService::class.java)

    @Singleton
    @Provides
    fun getVideoApiService():VideoApiService=RetrofitUtil.videoRetrofit.create(VideoApiService::class.java)

    @Singleton
    @Provides
    fun database(@ApplicationContext context: Context):ParkDataBase{
        return Room.databaseBuilder(context,ParkDataBase::class.java,"park2210.db")
            .allowMainThreadQueries()
            .build()
    }

    @Singleton
    @Provides
    fun getCommentDao(parkDataBase: ParkDataBase):CommentDao=parkDataBase.commentDao()

    @Singleton
    @Provides
    fun getHourseDao(parkDataBase: ParkDataBase):HourseDao=parkDataBase.hourseDao()

    @Singleton
    @Provides
    fun getSearchDao(parkDataBase: ParkDataBase):SearchDao=parkDataBase.searchDao()
}